class Solution {
public:
    vector<int> sortArrayByParity(vector<int>& nums) {
        int n = nums.size();
        vector<int> ret(n);
        int left = 0, right = n - 1;
        for (auto e : nums)
        {
            if (e % 2 == 0)
                ret[left++] = e;
            else
                ret[right--] = e;
        }
        return ret;
    }
};